//材料商订单详情
$('.fhuowc').click(function(){
  $('.tishi').css({
    display:'block'
  })
})
$('.quxiaod').click(function(){
  $('.tishi').css({
    display:'none'
  })
})

//判断有无商铺
var youwusp;

 //添加店铺
if(document.getElementById('tiansp')){
	var selcity;
	var sczl;
	var sc;
	var quwei;
	var adress;
	var name;
	var citynum;
	var city;
	adress = $('#xiandadress').val();
	name = $('#sjmingzi').val();
	selcity = "0531";
	sczl = 1;
	loginAction();
	//选择城市\
	 var url0 = basepath+'/form/city.do';
		var data0 = {city:"0531"};
		$.ajax({
	        url:url0,
	        async:false,
	        type:"post",
	        data:data0,
	        success:function(result){
	        	console.log(result);
	        	citynum = result.data.city.dicKey;
	        	selcity = result.data.city.dicKey;
	        	var cityArray = result.data.listCity;
	        	city = result.data.city.dicText;
	        	$('#xuandfcity').html(city);
	        	$("#sledcte").append("<option value='"+citynum+"'>"+city+"</option>");
               for(var i = 0;i < cityArray.length;i++){
             	  var dickty = cityArray[i].dicKey;
             	  var dicText = cityArray[i].dicText;
             	 if(citynum == dickty){
             		 
             	 }else{
             		 $("#sledcte").append("<option value='"+dickty+"'>"+dicText+"</option>");
             	 }
               }
               loginAction();
	       }
	    });
	
	
	
	var sel = document.getElementById('sledcte');
	var selected_val = sel.options[sel.selectedIndex].value;
	selcity = selected_val;
	
function seldctXCity(select){
	var sel = document.getElementById('sledcte');
	var selected_val = sel.options[sel.selectedIndex].value;
	var select_text = $('#sledcte option:selected').text();
	selcity = selected_val;
	
	$('#xuandfcity').html(select_text);
	loginAction();
	 sczl = 1;
	}
	
	$('.xgwos').click(function(){
		sczl = 1;
		 localStorage.setItem("sczld", "1");
		$('.xgwos').css({
		     background:'#b2bfa1',
		     color:'#fff'
		   })
		   $('.xgchuf').css({
		     background:'#fff',
		     color:'#000'
		   })
		    $('.xgweiy').css({
		     background:'#fff',
		     color:'#000'
		   })
		})

		$('.xgchuf').click(function(){
			sczl = 2;
			 localStorage.setItem("sczld", "2");
		$('.xgchuf').css({
		     background:'#b2bfa1',
		     color:'#fff'
		   })
		   $('.xgwos').css({
		     background:'#fff',
		     color:'#000'
		   })
		    $('.xgweiy').css({
		     background:'#fff',
		     color:'#000'
		   })
		})
		$('.xgweiy').click(function(){
			sczl = 3;
			 localStorage.setItem("sczld", "3");
		$('.xgweiy').css({
		     background:'#b2bfa1',
		     color:'#fff'
		   })
		   $('.xgchuf').css({
		     background:'#fff',
		     color:'#000'
		   })
		    $('.xgwos').css({
		     background:'#fff',
		     color:'#000'
		   })
		})
		
    	
  	   $(".xgdiyi p").click(loginAction);
		
  	 function loginAction(){
    	 var id;
   		if($(this).attr("data-id")==null){
   			id = 1;
   		}else{
   			id=$(this).attr("data-id");
   		}
   		var data ={areaId:id,city:selcity};
   		var url = basepath+'/market/find/shop.do';
   		$.ajax({
   	        url:url,
   	        type:"post",
   	        data:data,
   	        success:function(result){
   	        	var arrayid = result.data;
   	        	localStorage.setItem('arrayid',JSON.stringify(arrayid));
   	        
   	        	$('#xgfrdd').empty();
   	        	var array = result.data;
   	            var a = 9 / array.length - 0.25;
   	            for (var i = 0; i < array.length; i++) {
   	            $('#xgfrdd').append("<p class='tj"+i+"' onclick='thirdselectchang("+array[i].id+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height:0.8rem;border:0.5px solid #c7c7c7;background:#fff'>"+array[i].name+"</p>");
   	              $('.tj0').css({
   	               background:'#b2bfa1',
   	               color:'#fff'
   	             })
   	        
   	        }
   	       
   	         var shopid = result.data[0].id;
   	         thirdselectchang(shopid);
   	         selectchange(shopid);
   	      sc = shopid;
   	    /*  console.log(sc);*/
   	       }
   	    });
   		
  	 }
		
 	function selectchange(shopid){
 		sc = shopid;
 	   console.log('sc1='+sc);
		var dom;
		var vs = $('#xgfrdd p');
		var num = vs.length;
	
		for (var i = 0; i < num; i++) {
		  !function(i){
		     
		        $('.tj'+i).click(function(){
		        	//console.log(i);
		        if (i = 0) {
		         $('.tj0').click(function(){
		            $('.tj0').css({
		               background:'#b2bfa1',
		               color:'#fff'
		               })
		         })
		      }else{
		            $('.tj0').css({
		           background:'#fff',
		           color:'#000'
		            })  
		      }
		       !!dom ? dom.style.color = "":0;
		             !!dom ? dom.style.background = "":0;
		             this.style.color = "#fff";
		             this.style.background = "#b2bfa1";
		             dom = this;
		      });
		      
		  }(i);
		  
		}
		}
  	 	
	//三级
	function thirdselectchang(i){
		//console.log(i);
		 console.log('i1='+i);
		 sc = i;
	  $('#xiugaifour').empty();
	var url = basepath+'/market/find/area.do';
	var shopid = i;
	var data = {shopId:shopid};
		$.ajax({
	        url:url,
	        type:"post",
	        data:data,
	        success:function(result){
	        	//var arrayid = result.data;
   	        	//localStorage.setItem('arrayid',JSON.stringify(arrayid));
	        console.log(result);
	          var brray = result.data;
	      	for (var i = 0; i < brray.length; i++) {
	      	  $('#xiugaifour').append("<p class='xfour"+i+"' onclick='seleltthirdchange("+brray[i].id+")'  style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #e5e5e5;background:#fff'>"+brray[i].marketAreaName+"</p>");
	      	  $('.xfour0').css({
	      	  background:'#b2bfa1',
	      	  color:'#fff'
	      	})
	      	}
	      	var quid = brray[0].id;
	      	seleltthirdchange(quid);
	      	quwei = quid;
	      	/*console.log(quwei);*/
	       }
	    });
	 }
	
	
	function seleltthirdchange(shopid){
		quwei = shopid;
		console.log('quwei1='+quwei);

		  var dom;
		  var tvs = $('#xiugaifour p');
		  var tnum = tvs.length;
		 for (var i = 0; i < tnum; i++) {
		    !function(i){
		     
		        $('.xfour'+i).click(function(){
		   
		        if (i = 0) {
		         $('.xfour0').click(function(){
		            $('.xfour0').css({
		               background:'#b2bfa1',
		               color:'#fff'
		               })
		         })
		      }else{
		            $('.xfour0').css({
		           background:'#fff',
		           color:'#000'
		            })  
		      }
		       !!dom ? dom.style.color = "":0;
		             !!dom ? dom.style.background = "":0;
		             this.style.color = "#fff";
		             this.style.background = "#b2bfa1";
		             dom = this;
		      });
		      
		   }(i);
		  
		  }
		 }

	
	$('.tianjiadle').click(function(){
	var sczel =	localStorage.getItem("sczld");
		console.log(selcity);
		console.log('爱'+quwei);
		 console.log(sc);
		 console.log(sczl);
		 if($('#sjmingzi').val() == ''|| $('#xiandadress').val() == ''){
			 console.log('不能为空');
		 }else{
			 var url = basepath+'/market/addShop.do';
	
				var data = {shopName:$('#sjmingzi').val(),city:selcity,adress:$('#xiandadress').val(),typeId:sczel,marketId:sc,areaId:quwei};
			 $.ajax({
			        url:url,
			        type:"post",
			        async:false,
			        data:data,
			        success:function(result){
			        	console.log(result);
			        	  youwusp = 0;
			        	  localStorage.setItem("youwusp", "0");
			        	  history.go(-1);
			       }
			    });
		 }
		 
		
		
	});
	
}

var syouwusp = localStorage.getItem("youwusp"); 
console.log(syouwusp);
if (syouwusp == 0) {
  $('.dianpuzhans').css({
    display:'block'
  })
  $('.firstdianzong').css({
    display:'none'
  })
}else{
  $('.dianpuzhans').css({
    display:'none'
  })
  $('.firstdianzong').css({
    display:'block'
  })
}
if(document.getElementById('"guanlimang"')){
	
}
//编辑商铺
if(document.getElementById('binajisp')){
	var citug;
	var citynum;
	var city;
	
	var marketTypeId;
	var marketId;
	var marketAreaId;
	
	var id;
	var selcity;
	var sczl = 0;
	var dszl = 0;
	var ddts = 0;
	var sc;
	var quwei;
	var adress;
	var name;
	
	var typename ;
	var markName;
	var areaName;
	var shopAdress ;
	var shopName;
	var numcity;
	var thirdSelected = 0;
	var selectedThird = 0;
	
	
	var url1 = basepath+'/market/findShop.do';
	
	var data1 = {userId:'4'};
	 $.ajax({
	        url:url1,
	        type:"post",
	        async:false,
	        data:data1,
	        success:function(result){
	        	console.log(result);
	        	 myDian = result.data;
	        	 typename = myDian.marketTypeName;
	        	 markName = myDian.marketName;
	        	 areaName = myDian.marketAreaName;
	        	 shopAdress = myDian.adress;
	        	 shopName = myDian.shopName;
	        	 numcity = myDian.city;
	        	 marketId = myDian.marketId;
	        	 marketAreaId = myDian.marketAreaId;
	        	 marketTypeId = myDian.marketTypeId;
	        	 localStorage.setItem("sczl", marketTypeId);
	        	 id = myDian.id;
	        	 selcity = myDian.city;
	        /*	$('#sclexing').html(typename);
	        	$('#scmingzi').html(markName);
	        	$('#sccquwei').html(areaName);
	        	$('#scxiangaderss').html(shopAdress);
	        	$('#scjiamingzi').html(shopName);  */
	        	//选择城市\
	    		var sel = document.getElementById('sledcte');
	    		$('#xiandadress').val(shopAdress);
	        	$('#sjmingzi').val(shopName);
	       }
	    });
	 
	 console.log(shopName);
	 console.log(marketId);
	 console.log(marketAreaId);
	 
	 var url0 = basepath+'/form/city.do';
		var data0 = {city:numcity};
		$.ajax({
	        url:url0,
	        async:false,
	        type:"post",
	        data:data0,
	        success:function(result){
	        	console.log(result);
	        	citynum = result.data.city.dicKey;
	        	var cityArray = result.data.listCity;
	        	city = result.data.city.dicText;
	        	$('#xuandfcity').html(city);
	        	$("#sledcte").append("<option value='"+citynum+"'>"+city+"</option>");
                  for(var i = 0;i < cityArray.length;i++){
                	  var dickty = cityArray[i].dicKey;
                	  var dicText = cityArray[i].dicText;
                	 if(citynum == dickty){
                		 
                	 }else{
                		 $("#sledcte").append("<option value='"+dickty+"'>"+dicText+"</option>");
                	 }
                	 
                	 
                  }
	       }
	    });
		
		console.log(city);
	 
	 
	 
	function seldctXCity(select){
		var sel = document.getElementById('sledcte');
		var selected_val = sel.options[sel.selectedIndex].value;
		var select_text = $('#sledcte option:selected').text();
		selcity = selected_val;
		console.log('成交价'+selcity);
		$('#xuandfcity').html(select_text);
		citynum = selected_val;
		ddts = 11;
		citug = 1;
		loginAction();
		
		}
		if(marketTypeId == 1){
			$('.xgwos').css({
			     background:'#b2bfa1',
			     color:'#fff'
			   })
			   $('.xgchuf').css({
			     background:'#fff',
			     color:'#000'
			   })
			    $('.xgweiy').css({
			     background:'#fff',
			     color:'#000'
			   })
			
		}else if(marketTypeId == 2){
			$('.xgchuf').css({
			     background:'#b2bfa1',
			     color:'#fff'
			   })
			   $('.xgwos').css({
			     background:'#fff',
			     color:'#000'
			   })
			    $('.xgweiy').css({
			     background:'#fff',
			     color:'#000'
			   })
		}else if(marketTypeId == 3){
			$('.xgweiy').css({
			     background:'#b2bfa1',
			     color:'#fff'
			   })
			    $('.xgchuf').css({
			     background:'#fff',
			     color:'#000'
			   })
			    $('.xgwos').css({
			     background:'#fff',
			     color:'#000'
			   })
		}
		
		$('.xgwos').click(function(){
			sczl = 1;
			localStorage.setItem("sczl", "1");
			$('.xgwos').css({
			     background:'#b2bfa1',
			     color:'#fff'
			   })
			   $('.xgchuf').css({
			     background:'#fff',
			     color:'#000'
			   })
			    $('.xgweiy').css({
			     background:'#fff',
			     color:'#000'
			   })
			})

			$('.xgchuf').click(function(){
				sczl = 2;
				localStorage.setItem("sczl", "2");
			$('.xgchuf').css({
			     background:'#b2bfa1',
			     color:'#fff'
			   })
			   $('.xgwos').css({
			     background:'#fff',
			     color:'#000'
			   })
			    $('.xgweiy').css({
			     background:'#fff',
			     color:'#000'
			   })
			})
			$('.xgweiy').click(function(){
				sczl = 3;
				localStorage.setItem("sczl", "3");
			$('.xgweiy').css({
			     background:'#b2bfa1',
			     color:'#fff'
			   })
			   $('.xgchuf').css({
			     background:'#fff',
			     color:'#000'
			   })
			    $('.xgwos').css({
			     background:'#fff',
			     color:'#000'
			   })
			})
			
			loginAction();
	
  	
	    	
	  	   $(".xgdiyi p").click(loginAction);
			
	  	 function loginAction(){
	    	 var id;
	    	 if(sczl == 0){
	    		 id = marketTypeId;
	    	 }else{
	    		 id=$(this).attr("data-id"); 
	    	 }
	    	 if(ddts == 11){
	    		 id = 1;
	    	 }
	   		
	   		console.log('d点击:'+id);
	   		var data2 ={areaId:id,city:citynum};
	   		var url2 = basepath+'/market/find/shop.do';
	   		$.ajax({
	   	        url:url2,
	   	        async:false,
	   	        type:"post",
	   	        data:data2,
	   	        success:function(result){
	   	        	console.log('辅导费'+result.data);
	   	        	var arrayid = result.data;
	   	        	localStorage.setItem('arrayid',JSON.stringify(arrayid));
	   	        
	   	        	$('#xgfrdd').empty();
	   	        	var array = result.data;
	   	            var a = 9 / array.length - 0.25;
	   	           
	   	            for (var i = 0; i < array.length; i++) {
	   	            	
	   	            	
	   	            
	   	            	
	   	           $('#xgfrdd').append("<p class='tj"+i+"' onclick='thirdselectchangclick("+array[i].id+","+i+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height:0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden'>"+array[i].name+"</p>");
	   	      if(sczl != 0){
	   	    	$('.tj0').css({
	   	               background:'#b2bfa1',
	   	               color:'#fff'
	   	             })
	   	      }else{
	   	    	  
	   	    	if(marketId == array[i].id){
	   	    		thirdSelected = i;
	   	    		
   	            	$('.tj'+i).css({
	 	   	               background:'#b2bfa1',
	 	   	               color:'#fff'
	 	   	             })
	 	   	            
   	            }
	   	      }
	   	            	
	   	       if(citug == 1){
	   	    	$('.tj0').css({
	   	               background:'#b2bfa1',
	   	               color:'#fff'
	   	             })
	   	          citug = 0;
	   	       }     
	   	            
	   	            	
	   	        }
	   	       if(sczl == 0){
	   	    	
	   	         thirdselectchang(marketId);
	   	         selectchange(marketId);
	   	         sc = marketId;
	   	       }else{
	   	    	 var bbb = array[0].id;
	   	         thirdselectchang(bbb);
	   	         selectchange(bbb);
	   	         sc = bbb; 
	   	       }
	   	       
	   	    /*  console.log(sc);*/
	   	       }
	   	    });
	   		
	  	 }
			
	 	function selectchange(shopid){
	 		sc = shopid;
	 	   console.log('sc='+sc);
			var dom;
			var vs = $('#xgfrdd p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.tj'+i).click(function(){
			        	//console.log(i);
			        	 if (i == 0) {
					            $('.tj0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.tj0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
		}
	  	 	
		//三级
		function thirdselectchang(shopid,pp){
			  console.log('shopid='+shopid);
			  console.log('pp = '+pp);
			  
			  
		
			  if(marketId == shopid){
				  $('.tj'+pp).css({
		               background:'#fff',
		               color:'#000'
		               })
        	}else{
        		
		                $('.tj'+pp).css({
		               background:'#b2bfa1',
		               color:'#fff'
		               })
        	}
			//console.log(i);
			  sc = shopid;
			  ddts = 1;
		  $('#xiugaifour').empty();
		var url3 = basepath+'/market/find/area.do';
		var shopid = shopid;
		var data3 = {shopId:shopid};
			$.ajax({
		        url:url3,
		        async:false,
		        type:"post",
		        data:data3,
		        success:function(result){
		        	var arrayid = result.data;
	   	        	localStorage.setItem('arrayid',JSON.stringify(arrayid));
		        	//console.log(result);
		          var brray = result.data;
		      	for (var i = 0; i < brray.length; i++) {
		      	  $('#xiugaifour').append("<p class='xfour"+i+"' onclick='seleltthirdchangeclick("+brray[i].id+","+i+")'  style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #e5e5e5;background:#fff;overflow:hidden'>"+brray[i].marketAreaName+"</p>");
		      	 
		   	     
		   	    	 if(marketAreaId == brray[i].id){
		   	    		 
		   	    		selectedThird = i;
			      		  $('.xfour'+i).css({
					      	    background:'#b2bfa1',
					      	    color:'#fff'
					      	  })   	   
			      	  }
		   	      if(sczl != 0){
		   	    	 $('.xfour0').css({
				      	    background:'#b2bfa1',
				      	    color:'#fff'
				      	  })
				      	  	
		   	      }
		   	   if(dszl != 0){
		   	    	 $('.xfour0').css({
				      	    background:'#b2bfa1',
				      	    color:'#fff'
				      	  })
				      	  	
		   	      }
		   	  
		      	}
		      	if(dszl == 0){
		      		
			      	seleltthirdchange(marketAreaId);
			      	quwei = marketAreaId;
		      	}else{
		      		var quid = brray[0].id;
			      	seleltthirdchange(quid);
			      	quwei = quid;
		      	}
		      	
		      
		      	/*console.log(quwei);*/
		       }
		    });
			dszl ++;
		 }
		
		//三级
		function thirdselectchangclick(shopid,pp){
			  console.log('shopid='+shopid);
			  console.log('pp = '+pp);
			  
			  
			  $('.tj'+thirdSelected).css({
				  background:'#fff',
	               color:'#000'
	               })
	            
	               
	               thirdSelected= pp;
			
			  sc = shopid;
			  ddts = 1;
		  $('#xiugaifour').empty();
		var url3 = basepath+'/market/find/area.do';
		var shopid = shopid;
		var data3 = {shopId:shopid};
			$.ajax({
		        url:url3,
		        async:false,
		        type:"post",
		        data:data3,
		        success:function(result){
		        	var arrayid = result.data;
	   	        	localStorage.setItem('arrayid',JSON.stringify(arrayid));
		        	//console.log(result);
		          var brray = result.data;
		      	for (var i = 0; i < brray.length; i++) {
		      	  $('#xiugaifour').append("<p class='xfour"+i+"' onclick='seleltthirdchangeclick("+brray[i].id+","+i+")'  style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #e5e5e5;background:#fff;overflow:hidden'>"+brray[i].marketAreaName+"</p>");
		      	 
		   	     
		   	      if(sczl != 0){
		   	    	 $('.xfour0').css({
				      	    background:'#b2bfa1',
				      	    color:'#fff'
				      	  })
				      	  	
		   	      }
		   	   if(dszl != 0){
		   	    	 $('.xfour0').css({
				      	    background:'#b2bfa1',
				      	    color:'#fff'
				      	  })
				      	  	
		   	      }
		   	  
		      	}
		      	if(dszl == 0){
		      		
			      	seleltthirdchange(marketAreaId);
			      	quwei = marketAreaId;
		      	}else{
		      		var quid = brray[0].id;
			      	seleltthirdchange(quid);
			      	quwei = quid;
		      	}
		      	
		      
		      	/*console.log(quwei);*/
		       }
		    });
			dszl ++;
		 }
		
	function seleltthirdchange(shopid,areaid){
			quwei = shopid;
			
			 console.log('quwei='+quwei);
			 
			  var dom;
			  var tvs = $('#xiugaifour p');
			  var tnum = tvs.length;
			 for (var i = 0; i < tnum; i++) {
			    !function(i){
			    	
			        $('.xfour'+i).click(function(){
			        	  if (i == 0) {
			 		        
			 		            $('.xfour0').css({
			 		               background:'#b2bfa1',
			 		               color:'#fff'
			 		               })
			 		         
			 		      }else{
			 		            $('.xfour0').css({
			 		           background:'#fff',
			 		           color:'#000'
			 		            })  
			 		      }
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			   }(i);
			  
			  }
			 }
	function seleltthirdchangeclick(shopid,areaid){
		quwei = shopid;
		
		 console.log('quwei='+quwei);
		 
		 $('.xfour'+selectedThird).css({
			  background:'#fff',
              color:'#000'
              })
           
              
              selectedThird= areaid;
		
		 
		  var dom;
		  var tvs = $('#xiugaifour p');
		  var tnum = tvs.length;
		 for (var i = 0; i < tnum; i++) {
		    !function(i){
		    	
		        $('.xfour'+i).click(function(){
		        	  if (i == 0) {
		 		        
		 		            $('.xfour0').css({
		 		               background:'#b2bfa1',
		 		               color:'#fff'
		 		               })
		 		         
		 		      }else{
		 		            $('.xfour0').css({
		 		           background:'#fff',
		 		           color:'#000'
		 		            })  
		 		      }
		        	
		       !!dom ? dom.style.color = "":0;
		             !!dom ? dom.style.background = "":0;
		             this.style.color = "#fff";
		             this.style.background = "#b2bfa1";
		             dom = this;
		      });
		      
		   }(i);
		  
		  }
		 }
	
	//确认修改	
		$('.tianjiadle').click(function(){
		var sczll =	localStorage.getItem("sczl");
			console.log('FF:'+selcity);
			console.log('qq'+quwei);
			 console.log('ff='+sc);
			 console.log('gg='+sczl);
			 console.log('ii ='+id);
			 if($('#sjmingzi').val() == ''|| $('#xiandadress').val() == ''){
				 console.log('不能为空');
			 }else{
				 var url4 = basepath+'/market/updateShop.do';
		
					var data4 = {id:id,shopName:$('#sjmingzi').val(),city:selcity,adress:$('#xiandadress').val(),typeId:sczll,marketId:sc,areaId:quwei};
				   $.ajax({
				        url:url4,
				        async:false,
				        type:"post",
				        data:data4,
				        success:function(result){
				        	console.log(result);
				        sczl = 0;
				        dszl = 0;
				        history.go(-1);
				       }
				    });
			 }	
			
		});
}
//添加商品
var biglei;
var middlelei;
var smalllei;
var goodsName ;

var goodsNumber;

var goodsDanwei ;

var sendYN;
var sendPrice;

var anZYN;
var anZhuanPrice;
var goodsDetail;
var pinYN;
var pinrenNumber;
var pinTime;
var pinsendYN;
var pinsendPrice;
var pinanzYN ;
var pinanzhuangPrice;

if(document.getElementById('tianjiasp')){
	var url = basepath+'/shop/typeBig.do';
	  $.ajax({
	        url:url,
	        async:false,
	        type:"get",
	        success:function(result){
	        	console.log(result);
	        	var carray = result.data;
	        	for(var i = 0;i < carray.length;i++){
	        		 $('.xgdiyi').append("<p class='xgwos"+i+"' onclick='zhongleixians("+carray[i].typeBigId+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden;font-size:0.36rem'>"+carray[i].typeBigName+"</p>");
	        	}
	        	$('.xgwos0').css({
	        		 background:'#b2bfa1',
		               color:'#fff'
	        	})
	        	var aa = carray[0].typeBigId;
	        	zhongleixians(aa);
	        	biglei = carray[0].typeBigId
	       }
	    });
	  
	  function zhongleixians(d){
		  biglei = d;
			var dom;
			var vs = $('.xgdiyi p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.xgwos'+i).click(function(){
			        	//console.log(i);
			        	 if (i == 0) {
					            $('.xgwos0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.xgwos0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
			$('.xgdier').empty();
		  var urlzhong = basepath+'/shop/typeMiddle.do';
		 var data = {bigId:d};
		 console.log(data);
		  $.ajax({
		        url:urlzhong,
		        async:false,
		        type:"post",
		        data:data,
		        success:function(result){
		        	console.log(result);
		        	var zarray = result.data;
		        	for(var i = 0;i < zarray.length;i++){
		        		 $('.xgdier').append("<p class='zlei"+i+"' onclick='xiaoleixianshi("+zarray[i].typeMiddleId+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden;font-size:0.36rem'>"+zarray[i].typeMiddleName+"</p>");
		        	}
		        	$('.zlei0').css({
		        		 background:'#b2bfa1',
			               color:'#fff'
		        	})
		        	var xiaole = zarray[0].typeMiddleId;
			        xiaoleixianshi(xiaole);
			        middlelei = zarray[0].typeMiddleId;
		       }
		        
		    });
	  }
	  
	  function xiaoleixianshi(dd){
		  middlelei = dd;
		  var dom;
			var vs = $('.xgdier p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.zlei'+i).click(function(){
			        	//console.log(i);
			        	 if (i == 0) {
					            $('.zlei0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.zlei0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
		  $('.xiugaidisan').empty();
		  var urlxiaolei = basepath+'/shop/typeSmall.do';
		  var data = {middleId:dd};
		  $.ajax({
		        url:urlxiaolei,
		        async:false,
		        type:"post",
		        data:data,
		        success:function(result){
		        	console.log(result);
		        	var ziarray = result.data;
		        	for(var i = 0;i < ziarray.length;i++){
		        		 $('.xiugaidisan').append("<p class='zilei"+i+"' onclick='xiaoleixianshiclick("+ziarray[i].typeSmallId+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden;font-size:0.36rem'>"+ziarray[i].typeSmallName+"</p>");
		        	}
		        	$('.zilei0').css({
		        		 background:'#b2bfa1',
			               color:'#fff'
		        	})
		        	
		        	 xiaoleixianshiclick();
		        	smalllei = ziarray[0].typeSmallId;
		       }
		       
		    });
	  }
	  
	function xiaoleixianshiclick(fff){
		smalllei = fff;
		 var dom;
			var vs = $('.xiugaidisan p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.zilei'+i).click(function(){
			        	//console.log(i);
			        	 if (i == 0) {
					            $('.zilei0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.zilei0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
	}

	
	//添加型号
	
	 var picone;
	 var pictwo;
	var xianzyix;
	xianzyix = 0;
	 //图片上传
	//添加商品1 
	  if(document.getElementById('shctp1')){
		  initwebuploader();
		  function initwebuploader(){
			  var uploader = WebUploader.create({

				    // 选完文件后，是否自动上传。
				    auto: true,

				    // swf文件路径
				   // swf:'../js/Uploader.swf',

				    // 文件接收服务端。
				    server: basepath+'/upload/upImg.do',

				    // 选择文件的按钮。可选。
				    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
				    pick: {
				    	id:'#filePickerd',
				    	multiple:false,//当个文件 
				    },
				    fileNumLimit: 1,//限制单张
				   // resize : true,//压缩
				    duplicate :true,
				    // 只允许选择图片文件。
				    accept: {
				        title: 'Images',
				        extensions: 'gif,jpg,jpeg,bmp,png',
				        mimeTypes: 'image/*'
				    }
				});
			  
			  uploader.on( 'fileQueued', function( file ) { 
				  $("#fileList").empty();
				  var $list = $("#fileList"), 
				  $li = $( 
				  '<div id="' + file.id + '" class="file-item thumbnail">' + 
				  '<img class="shangchuantu" style="width:8rem">' + '</div>'
				  ), 
				
				  $img = $li.find('img'); 
				   
				   
				  // $list为容器jQuery实例 
				  $list.append( $li ); 
				   
				  // 创建缩略图 
				  uploader.makeThumb( file, function( error, src ) { 
				  if ( error ) { 
				  $img.replaceWith('<span>不能预览</span>'); 
				  return; 
				  } 
				 
				  $img.attr( 'src', src ); 
				  }, 100, 100 ); //100x100为缩略图尺寸 
				 });
			  uploader.on("uploadSuccess", function (file,response) {
				  console.log(response.data.id);
				  picone = response.data.id;
			  })
			  uploader.on("uploadFinished", function (file,src) {
				 
			        uploader.destroy();//重复上传,县销毁,在重新启动
			        
			        initwebuploader();
			    });
			  
			  
		  }
		  
		 }
/*	 var options =
      {
          thumbBox: '.thumbBox',
          spinner: '.spinner',
          imgSrc: ''
      }
      var cropper = $('.imageBox').cropbox(options);
      $('#xhdui').on('change', function(){
    	  $('.imageBox').css({
    		  display:'block'
    	  })
    	   $('.thumbBox').css({
    		  display:'block'
    	  })
          var reader = new FileReader();
          reader.onload = function(e) {
              options.imgSrc = e.target.result;
              cropper = $('.imageBox').cropbox(options);
          }
          reader.readAsDataURL(this.files[0]);
          this.files = [];
      })*/
     
	var pdd;
	$('.xqxinghao').click(function(){
		var xianzi = localStorage.getItem('xianzi');
		
		var cha = 3 - xianzi;
		
			if(xianzyix >= cha){
				  alert('最多只能添加三个规格');
				}else{
					 $('.tishi').css({
					      display:'block'
					    })  
					    pdd = 0;
					    $("html, body").animate({
					          "scroll-top":0
					        },0);
				}
		
		
		
	   
	})

	var inote;
	var cicunc;
	var yansec;
	var jiagec;
	var inpts = 0;
	var xinhaoarray = new Array();
	var xuanzearray = new Array();
	var pinxinhor = new Array();
	var pinXuanZ = new Array();
	
	$('.quedind').click(function(){
/*		 $('.imageBox').css({
   		  display:'none'
   	  })
   	   $('.thumbBox').css({
   		  display:'none'
   	  })
         var img = cropper.getDataURL();
         var tupian = Base64.decode64(data_url[img.length .. -1]);
         var pos = img.indexOf("4")+2;
         img = img.substring(pos, img.length - pos);//去掉Base64:开头的标识字符
         img = encodeURIComponent(img);
         picone = img;
         console.log(picone);
       */
         
		xianzyix ++;
		 //localStorage.setItem("xuanxianzhi",xuanxianzhi);
	  if (pdd == 0) {
	     $('.tishi').css({
	      display:'none'
	    })  
	    inote = $('.shuruguig').val();
	    cicunc = $('.chicun').val();
	    yansec = $('.yanse').val();
	    jiagec = $('.jiage').val();
	    
	    xinhaoarray.splice(0,xinhaoarray.length);
	    xinhaoarray["model"] = inote;
	    xinhaoarray["size"] = cicunc;
	    xinhaoarray["color"] = yansec;
	    xinhaoarray["price"] = jiagec;
	    xinhaoarray["pic"] = picone;
	    
	    var j = [];
	    	j["model"] = xinhaoarray.model;
	 	    j["size"] = xinhaoarray.size;
	 	    j["color"] = xinhaoarray.color;
	 	    j["price"] = xinhaoarray.price;  
	 	    j["pic"] = xinhaoarray.pic;   
	    console.log(j);
	    xuanzearray.push(j);
	    
	    var div = $('<div id="by'+inpts+'" class="baoxinghao"></div>');
	    var span = "<p id='xh"+inote+"' class='xqxinghaox'>"+inote+"</p>"+"<p id='xh"+inote+"'  class='xqxinghaox'>"+cicunc+"</p>"+"<p id='xh"+inote+"'  class='xqxinghaox'>"+yansec+"</p>"+"<p id='xh"+yansec+"'  class='xqxinghaox'>"+jiagec+"</p>";
	    var p = "<p id='dexh"+inpts+"' class='addtu7' onclick='delete_system("+inpts+")'></p>";
	   var img = $('<img id="pic'+inpts+'" class="xingtu" src="'+basepath+'/attachment/'+picone+'.do" />');
	   
	    div.append(span);
	       
	   $('.xinghaotj').append(div);
	   $('.xinghaotj').append(p);
	   $('.xinghaotj').append(img);
	   inpts ++;
	   console.log(xinhaoarray);
	   
	  console.log(xuanzearray);
	  
	   
	  }
	  
	})


	//选择型号
	var xuad;
	var xing;
	$('.xuanzvhai').click(function(){
	    $('.xuanzvhai').css({
	      display:'none'
	    })  
	    
	})

	$('.xuanzcdhai').click(function(){
	    $('.xuanzvhai').css({
	      display:'block'
	    })  
	    xuad = 0;
	    var p = [];
	    $('.xinghaohuizong').empty();
	    for (var i = 0; i < xuanzearray.length; i++) {
	    
	    p = xuanzearray[i];
	    var div = $('<div id="bc'+i+'" class="baoyiceng2" onclick="tanchuyinclick('+i+')"></div>');
	     var span = "<p id='xh"+p.model+"' class='xqxinghaox'>"+p.model+"</p>"+"<p id='xh"+p.model+"'  class='xqxinghaox'>"+p.size+"</p>"+"<p id='xh"+p.model+"'  class='xqxinghaox'>"+p.color+"</p>"+"<p id='xh"+p.model+"'  class='xqxinghaox'>"+p.price+"</p>";
	    div.append(span);
	    $('.xinghaohuizong').append(div);
	  }
	})
	function tanchuyinclick(h){
	   $('.xuanzvhai').css({
	      display:'none'
	    })
	   $('.pindandanjia').css({
	      display:'block'
	    })
	   xing = h;
	   console.log(h);
	   $('.pindanxinhao').empty();
	   var d = xuanzearray[h];
	   var div = $('<div id="zs'+h+'" class="baoyiceng"></div>');
	   var span = "<p id='xh"+d.model+"' class='xqxinghaox'>"+d.model+"</p>"+"<p id='xh"+d.model+"'  class='xqxinghaox'>"+d.size+"</p>"+"<p id='xh"+d.model+"'  class='xqxinghaox'>"+d.color+"</p>"+"<p id='xh"+d.model+"'  class='xqxinghaox'>"+d.price+"</p>";   
	   div.append(span);
	    $('.pindanxinhao').append(div);
	  
	}


	$('.pindanqu').click(function(){
	    $('.pindandanjia').css({
	      display:'none'
	    })  
	    
	})

	$('.pindanjiat').click(function(){
	    $('.pindandanjia').css({
	      display:'none'
	    })  
	    
	   var xick = sessionStorage.getItem(xing);
	    console.log(xick);
	   /*if(xing == xick){
		  alert('您已经添加过该商品')
	   }else{*/
		   var ijd = $('.pindanjiage').val();
		    var w = xuanzearray[xing];
		    pinxinhor.splice(0,xinhaoarray.length);
		    pinxinhor["goodsModelId"] = w.model;
		    pinxinhor["size"] = w.size;
		    pinxinhor["color"] = w.color;
		    pinxinhor["pinPrice"] = ijd;
		    var dp = new Array();
		    dp["goodsModelId"] = pinxinhor.goodsModelId;
		    dp["size"] = pinxinhor.size;
		    dp["color"] = pinxinhor.color;
		    dp["pinPrice"] = pinxinhor.pinPrice;
		    pinXuanZ.push(dp);
		    console.log("w="+w.model);
		    console.log("pin ="+pinxinhor);
		    console.log(pinXuanZ);
		    sessionStorage.setItem(xing, xing);
		    
			 var divv = $('<div id="pj'+xing+'" class="baoxinghao"></div>');
			 var span = "<p id='xh"+w.model+"' class='xqxinghaox'>"+w.model+"</p>"+"<p id='xh"+w.model+"'  class='xqxinghaox'>"+w.size+"</p>"+"<p id='xh"+w.model+"'  class='xqxinghaox'>"+w.color+"</p>"+"<p id='xh"+w.model+"'  class='xqxinghaox'>"+ijd+"</p>";
			var p = "<p id='dexfdh"+xing+"' class='addtu7' onclick='delete_system1("+xing+")'></p>";
			 divv.append(span);
			$('.xuanzwxinghao').append(divv);
			$('.xuanzwxinghao').append(p);
	  /* }*/
	   
	   
		    
	})
	function delete_system(flag){
		xianzyix --;
		if(xianzyix <= 0){
			xianzyix = 0;
		}
		console.log(xianzyix);
		 //
		//根元素不删除
		 console.log(flag);
		   xuanzearray.splice(flag,1);

		   console.log(xuanzearray);
		   document.getElementById("pic" + flag + "").remove();
		   document.getElementById("by" + flag + "").remove();
		   document.getElementById("dexh" + flag + "").remove();
		 if(pinXuanZ.length == 0){
			 
		 }else{
			 delete_system1(flag);
		 }
		  
		}
	function delete_system1(q){
	//根元素不删除 
	   document.getElementById("pj" + q + "").remove();
	   document.getElementById("dexfdh" + q + "").remove();
	}
	
	
/*	  //添加商品2
	  if(document.getElementById('shctp2')){
		  initwebuploader2();
		  function initwebuploader2(){
			  var uploader2 = WebUploader.create({

				    // 选完文件后，是否自动上传。
				    auto: true,

				    // swf文件路径
				   // swf:'../js/Uploader.swf',

				    // 文件接收服务端。
				    server: basepath+'/upload/upImg.do',

				    // 选择文件的按钮。可选。
				    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
				    pick: {
				    	id:'#filePickerd2',
				    	multiple:false,//当个文件 
				    },
				    fileNumLimit: 1,//限制单张
				   // resize : true,//压缩
				    duplicate :true,
				    // 只允许选择图片文件。
				    accept: {
				        title: 'Images',
				        extensions: 'gif,jpg,jpeg,bmp,png',
				        mimeTypes: 'image/*'
				    }
				});
			  
			  uploader2.on( 'fileQueued', function( file ) { 
				  $("#fileList2").empty();
				  var $list = $("#fileList2"), 
				  $li = $( 
				  '<div id="' + file.id + '" class="file-item thumbnail">' + 
				  '<img class="shangchuantu">' + '</div>'
				  ), 
				
				  $img = $li.find('img'); 
				   
				   
				  // $list为容器jQuery实例 
				  $list.append( $li ); 
				   
				  // 创建缩略图 
				  uploader2.makeThumb( file, function( error, src ) { 
				  if ( error ) { 
				  $img.replaceWith('<span>不能预览</span>'); 
				  return; 
				  } 
				   
				  $img.attr( 'src', src ); 
				  }, 100, 100 ); //100x100为缩略图尺寸 
				 });
			  uploader2.on("uploadSuccess", function (file,response) {
				  console.log(response.data.id);
				  pictwo = response.data.id;
			  })
			  uploader2.on("uploadFinished", function () {

			        uploader2.destroy();//重复上传,县销毁,在重新启动
			        
			        initwebuploader2();
			    });
			
			 
		  }
		  
		 }
	 */
		//开关
		 var chk = document.getElementById('ios-checkbox');
		 pinYN = 1;
		function kaiguan1(){
		 
		if (chk.checked == false) {
			pinYN  = 0;
		  console.log(chk.checked);
		}else{
			pinYN  = 1;
		  console.log(chk.checked);
		}
		if(pinYN == 0){
			$('.shifouzhankai').css({
				display:'block'
			})
		}else{
			$('.shifouzhankai').css({
				display:'none'
			})
		}
		
	}
		
		//否免费配送
		sendYN = 1;
			function peisongclick(){
			  var peisongf = document.getElementById('peisonggaoqi').peisong;
			   for (var i = 0; i < peisongf.length; i++) {
			    if (peisongf[i].checked) {
			      var pesf = peisongf[i].value;
			    console.log(pesf);
			    sendYN  = pesf;
			  }
			    
			}
			}
			//是否免费安装
			anZYN = 1;
			function anzhuangclick(){
			  var pinaz = document.getElementById('anzhuagngaoqi').anzhuang;
			   for (var i = 0; i < pinaz.length; i++) {
			    if (pinaz[i].checked) {
			      var pesf = pinaz[i].value;
			    console.log(pesf);
			    anZYN  = pesf;
			  }
			    
			}
			}
			
			//拼单人数
			 pinrenNumber = 2;
			function seldctpinren(){
				var sel = document.getElementById('pinren');
				var selected_val = sel.options[sel.selectedIndex].value;
				var select_text = $('#pinren option:selected').text();
				pinrenNumber = selected_val;
				console.log(selected_val);
				
				}
			//p拼单周期
			  pinTime= 3;
			function seldcttime(){
				var pintime = document.getElementById('pintime');
				var pintime_val = pintime.options[pintime.selectedIndex].value;
				var pintime_text = $('#pintime option:selected').text();
				  pinTime = pintime_val;
				console.log(pintime_val);	
				}
			//拼团是否免费配送
			 pinsendYN = 1;
			function pinpeisongclick(){
			  var peisongf = document.getElementById('pinpeisongfei').pinpeisong;
			   for (var i = 0; i < peisongf.length; i++) {
			    if (peisongf[i].checked) {
			      var pesf = peisongf[i].value;
			    console.log(pesf);
			    pinsendYN  = pesf;
			  }
			    
			}
			}

			 
			
			//拼团是否免费安装
			  pinanzYN = 1;
			function pinanzhuangclick(){
			  var pinaz = document.getElementById('pinanzhuangfei').pinanzhuang;
			   for (var i = 0; i < pinaz.length; i++) {
			    if (pinaz[i].checked) {
			      var pesf = pinaz[i].value;
			    console.log(pesf);
			    pinanzYN  = pesf;
			  }
			    
			}
			}
	//添加
		 $('.tiajiagoods').click(function(){
			 localStorage.setItem("xianzyix",xianzyix);
			 goodsName = $('.godsname').val();
			 goodsNumber = $('.gosdnum').val();
			 goodsDanwei = $('.gosdanwei').val();
			 sendPrice  = $('.godsendprce').val();
			 anZhuanPrice  = $('.anzhuanf').val();
			 goodsDetail  = $('#miaosu').val();
			 pinsendPrice  = $('.shufuekfk').val();
			 pinanzhuangPrice  = $('.pinanzhuanf').val();
			 console.log(goodsName);
			 
			 var customerArray = new Array();
			 var pincustomerArray = new Array();
			 var picarray = new Array();
			 for(var i = 0;i<xuanzearray.length;i++){
				 customerArray.push({model:xuanzearray[i].model,size:xuanzearray[i].size,color:xuanzearray[i].color,price:xuanzearray[i].price,imgUrl:xuanzearray[i].pic});
			 }
			 for(var i = 0;i<pinXuanZ.length;i++){
				 pincustomerArray.push({goodsModelId:'',pinPrice:pinXuanZ[i].pinPrice});
			 }
			 picarray.push({goodsId:'',resourseId:picone});
			 picarray.push({goodsId:'',resourseId:pictwo});
			/* pincustomerArray.push({goodsModelId:'',pinPrice:'12',});
			 pincustomerArray.push({goodsModelId:'',pinPrice:'14',});*/
			 console.log(customerArray);
			 console.log(pincustomerArray);
			 var urltianjia = basepath+'/goods/save2.do';
			  var data = {
					  id:"",
					  name:goodsName,
					  amount:goodsNumber,
					  unit:goodsDanwei,
					  freeSend:sendYN,
					  sendPrice:sendPrice,
					  hasInstall:anZYN,
					  installPrice:anZhuanPrice,
					  description:goodsDetail,
					  typeBigId:biglei,
					  typeMiddleId:middlelei,
					  typeSmallId:smalllei,
					  shopId:"",
					  remark:"",
					  isOpenpin:pinYN,
					  pinNums:pinrenNumber,
					  pinTime:pinTime,
					  pinFreeSend:pinsendYN,
					  pinSendPrice:pinsendPrice,
					  pinHasInstall:pinanzYN,
					  pinInstallPrice:pinanzhuangPrice,
					  goodsPic:picarray,
					  goodsModel:customerArray,
					  goodsModelPin:pincustomerArray,
					  };
			  console.log(data);
			  $.ajax({
				  	contentType : "application/json ; charset=utf-8",
				  	url:urltianjia,
			        async:false,
			        type:"post",
			        dataType: "json", 
			        data:JSON.stringify(data),
			        success:function(result){
			        	console.log(result);
			        	sessionStorage.removeItem(xing);
			        	 window.location.href=basepath + "/form/addGooDsShop.do";
			       }
			 
			    });
		 })
}

var tiaotiao;
//展示开店商品
if(document.getElementById('shangpinzs')){
	 var url = basepath+'/goods/list.do';
	  var data = {id:'',startPage:'0',pageSize:'10'};
	  $.ajax({
	        url:url,
	        async:false,
	        type:"post",
	        data:data,
	        success:function(result){
	        	console.log(result);
	        	var sparray = result.data.list;
	        	for(var i = 0;i < sparray.length;i++){
	        		var div = $('<div class="renwuliebiao" onclick="tiaozhuan('+sparray[i].id+')"></div>');
	        		var dl = $('<dl class="jianjiansha"></dl>');
	        		var dt = $('<dt class="adtouxiang"></dt>');
	        		var dd= $('<dd class="renwuxinxi"></dd>')
	        		var dd2 = $('<dd class="addright"></dd>')
	        		var imgg = $('<img id="imgg'+i+'" src = '+basepath+'/attachment/'+sparray[i].imgUrl+'.do>');
	        		dt.append(imgg);
	        		console.log(sparray[i].imgUrl);
	        		dd.append('<p class="name">'+sparray[i].name+'</p> '+'<p class="addkucun">库存量:<span>'+sparray[i].amount+'</span></p>'+'<p class="anlishu">销量:<span>'+sparray[i].sales+'</span> 万</p>'+'<p class="linian">配送费:<span>'+sparray[i].sendPrice+'元／公里</span></p>'+'<p class="phone">￥'+sparray[i].price+'</p>');
	        		if(sparray[i].isOpenPin == 0){
	        			dd2.append('<p class="yikaiqipd">已开启拼单</p>'+'<p class="rightt"></p>');
	        		}else{
	        			dd2.append('<p class="weikaiqipd"></p>'+'<p class="rightt"></p>');
	        		}  		
	        		div.append(dl);
	        		dl.append(dt);
	        		dl.append(dd);
	        		dl.append(dd2);
	        		 $('.spzshi').append(div);
	        		 
	        	}	
	       }
	       
	    });  	  
}
//跳转商品详情
function tiaozhuan(i){
	  window.location.href=basepath + "/form/SGShopXq.do";
	  console.log(i);
	  localStorage.setItem("usid",i);
}
//每件商品详情

if(document.getElementById('spxiangqigaoqi')){
	 var iid;
	var tt = localStorage.getItem("usid");
		var url = basepath+'/goods/listAll.do';
		  var data = {id:tt};
		  $.ajax({
		        url:url,
		        async:false,
		        type:"post",
		        data:data,
		        success:function(result){
		        	console.log(result);
		        	var str = JSON.stringify(result.data);
		        	localStorage.setItem("Shopdata",str);
		        	var parray = result.data[0];
		        	var pricarray = parray.goodsModel;
		        	var picarray = parray.goodsPic;
		        	var pinarray = parray.goodsModelPin;
		        	iid = parray.id;
		          $('#kedwos').text(parray.typeBigName);
		          console.log(parray.typeBigName);
		      	  $('#zhonleiwos').text(parray.typeMiddleName);
		      	  $('#zileidiaode').text(parray.typeSmallName);
		      	  $('#spmingzi').text(parray.name);
		      	  $('#spkucunl').text(parray.amount);
		      	  if(parray.freeSend == 1){
		      		$('#peisongYprorN').text("是");
		      	  }else{
		      		$('#peisongYprorN').text("否");
		      	  }
		      	 if(parray.hasInstall == 1){
		      		$('#anzhuagnYprorN').text("是");
		      	 }else{
		      		$('#anzhuagnYprorN').text("否");
		      	 }
		      	 $('#anzhuangjiage').text(parray.installPrice);
		      	 $('#spdanweil').text(parray.unit);
		      	  $('#spdnajial').text(parray.sendPrice);
		      	  $('#miaosu').val(parray.remark);
		      	  //规格
		      	  console.log(pricarray);
		      	  for(var i = 0;i < pricarray.length;i++){
		      		 var div = $('<div class="baoxinghao"></div>')
		      		  div.append('<span id="xinghaozhans" class="xqxinghaox">'+pricarray[i].model+'</span>'+'<span id="cicunzhans" class="xqxinghaox">'+pricarray[i].size+'</span>'+'<span id="yansezhans" class="xqxinghaox">'+pricarray[i].color+'</span>'+'<span id="jiagezhans" class="xqxinghaox">'+pricarray[i].price+'元</span>')
		      		   var img = $('<img  class="xingtu xingtu1" src="'+basepath+'/attachment/'+pricarray[i].imgUrl+'.do" />');
		      		  $('.donttianjia').append(div);
		      		 $('.donttianjia').append(img);
		      	  }
		      	
		      	 //图片
		      	/*  var pic1 = picarray[0].resourseId;
		      	  var pic2 = picarray[1].resourseId;
		         var path = basepath+'/attachment/'+pic1+'.do';
		         var path2 = basepath+'/attachment/'+pic2+'.do';
		        
		      	  $('#tuyixl').attr('src',path);
		      	  $('#tuerxl').attr("src",path2);*/
		      	  //拼单
		        var pinyyd = parray.isOpenpin;
		        if(pinyyd == 0){
		        	 $('#pinsfou').text('是');
		        }else{
		        	$('#pinsfou').text('否');
		        }
		      	var pinsendy = parray.pinFreeSend;
		      	if(pinsendy == 1){
		      		$('#pinshifoupei').text('是');
		      	}else{
		      		$('#pinshifoupei').text('否');
		      	}
		      	var anzhunys = parray.pinHasInstall;
		      	if(anzhunys == 1){
		      		$('#pinshifouanzjd').text('是');
		      	}else{
		      		$('#pinshifouanzjd').text('否');
		      	}
		      	 $('#pinrenshu').text(parray.pinNums);
		      	
		      	 $('#pinshijian').text(parray.pinTime);
		      	 
		      	 $('#pinsendjigedp').text(parray.sendPrice);
		      	 
		      	 $('#pinanzhuangjiadeg').text(parray.pinInstallPrice);
		      	 console.log(pricarray);
		      	for(var i = 0;i < pinarray.length;i++){
		      	
		      		 var div = $('<div class="baoxinghao baonao"></div>');
		      		  div.append('<span id="xinghaozhans" class="xqxinghaox pinxiaodd">'+pricarray[i].model+'</span>'+'<span id="cicunzhans" class="xqxinghaox pinxiaodd">'+pricarray[i].size+'</span>'+'<span id="yansezhans" class="xqxinghaox pinxiaodd">'+pricarray[i].color+'</span>'+'<span id="jiagezhans" class="xqxinghaox pinxiaodd">'+pinarray[i].pinPrice+'元</span>')
		      		
		      		  $('.pinxuanzdongtaijia').append(div);
		      		
		      	  }
		      	 
		       }
		       
		    });
	
		//删除商品
		  $('.xiajiashpi').click(function(){
			  var url = basepath+'/goods/delete.do';
			  var data = {id:iid};
			  $.ajax({
			        url:url,
			        async:false,
			        type:"post",
			        data:data,
			        success:function(result){
			        console.log(result);
			        }
			       
			    });
		  })
	  //下架商品
		 $('.xiajiasp').click(function(){
			  var url = basepath+'/goods/xiajia.do';
			  var data = {id:iid};
			  $.ajax({
			        url:url,
			        async:false,
			        type:"post",
			        data:data,
			        success:function(result){
			        console.log(result);
			        }
			       
			    });
		  }) 
	  
}
//编辑商品
var daleitiao = "x";
var zhongleitiao = "y";
var xiaoleitiao = "z";
var bian;
var xuanbig;
var xuanmiddle;
var xuansmall;
if (document.getElementById('xiugiahchagaoqi')){
	//选择参数
	var str =  localStorage.getItem("Shopdata");
	var shoparray = new Array();
	shoparray = JSON.parse(str);
	console.log(shoparray);
	xuanbig = shoparray[0].typeBigId;
	xuanmiddle = shoparray[0].typeMiddleId;
	xuansmall = shoparray[0].typeSmallId;
	
	var url = basepath+'/shop/typeBig.do';
	  $.ajax({
	        url:url,
	        async:false,
	        type:"get",
	        success:function(result){
	        	console.log(result);
	        	var carray = result.data;
	        	for(var i = 0;i < carray.length;i++){
	        		 $('.xgdiyi').append("<p class='xgwos"+i+"' onclick='zhongleifun("+carray[i].typeBigId+","+i+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden;font-size:0.36rem'>"+carray[i].typeBigName+"</p>");
	        		 if(carray[i].typeBigId == shoparray[0].typeBigId){
	        			 daleitiao = i;
	        			 $('.xgwos'+i).css({
	    	        		 background:'#b2bfa1',
	    		               color:'#fff'
	    	        	})
	        		 }
	        	}
	        	if(xuanbig == shoparray[0].typeBigId){
	        		//var middleId = shoparray[0].typeBigId;
		            zhongleifun(xuanbig,0);
	        	}else{
	        		
	        		var middleId = carray[0].typeBigId;
		            zhongleifun(middleId,0);
	        	}
	        	
	       }
	    });
	  
	  function zhongleifun(middleId,dg){
		  console.log(middleId,dg);
		  xuanbig = middleId;
		  if(middleId == shoparray[0].typeBigId){
			  $('.xgwos'+daleitiao).css({
				  background:'#b2bfa1',
	               color:'#fff'
			  })
		  }else{
			  $('.xgwos'+daleitiao).css({
				  background:'#fff',
	               color:'#000'
			  })
			  daleitiao == dg;
		  }
		  
		 
		  var dom;
			var vs = $('.xgdiyi p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.xgwos'+i).click(function(){
			        	//console.log(i);
			        	 if (i == 0) {
					            $('.xgwos0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.xgwos0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
		 
			$('.xgdier').empty();
			  var urlzhong = basepath+'/shop/typeMiddle.do';
			 var data = {bigId:middleId};
			  $.ajax({
			        url:urlzhong,
			        async:false,
			        type:"post",
			        data:data,
			        success:function(result){
			        	console.log(result);
			        	var zarray = result.data;
			        	for(var i = 0;i < zarray.length;i++){
			        		 $('.xgdier').append("<p class='zlei"+i+"' onclick='zileifun("+zarray[i].typeMiddleId+","+i+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden;font-size:0.36rem'>"+zarray[i].typeMiddleName+"</p>");
			        		 if(zarray[i].typeMiddleId == shoparray[0].typeMiddleId){
			        			 zhongleitiao = i;
			        			 $('.zlei'+i).css({
			    	        		 background:'#b2bfa1',
			    		               color:'#fff'
			    	        	})
			        		 }
			        	}
			        	if(middleId == shoparray[0].typeBigId){
			        		var smallId = shoparray[0].typeMiddleId;
				        	zileifun(smallId);
			        	}else{
			        		console.log('我们不一样');
			        		 $('.zlei0').css({
		    	        		 background:'#b2bfa1',
		    		               color:'#fff'
		    	        	})
			        		var asllId = zarray[0].typeMiddleId;
				        	zileifun(asllId);
			        		xuanmiddle = asllId;
			        	}
			        	
			       }
			        
			    });
	  }
	  
	 function zileifun(smallId,dp){
		 xuanmiddle = smallId;
		 console.log(xuanmiddle);
		
			if(smallId == shoparray[0].typeMiddleId){
				$('.zlei'+zhongleitiao).css({
					background:'#b2bfa1',
		               color:'#fff'
				 })
			}else{
				 $('.zlei'+zhongleitiao).css({
					 background:'#fff',
			           color:'#000'
				 })
				 zhongleitiao = dp;
				 $('.zlei0').css({
	        		 background:'#b2bfa1',
		               color:'#fff'
	        	})
			}
		
		 var dom;
			var vs = $('.xgdier p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.zlei'+i).click(function(){
			        	//console.log(i);
			        	 if (i == 0) {
					            $('.zlei0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.zlei0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
		  $('.xiugaidisan').empty();
		  var url = basepath+'/shop/typeSmall.do';
		  var data = {middleId:smallId};
		  $.ajax({
		        url:url,
		        async:false,
		        type:"post",
		        data:data,
		        success:function(result){
		        	console.log(result);
		        	var ziarray = result.data;
		        	for(var i = 0;i < ziarray.length;i++){
		        		 $('.xiugaidisan').append("<p class='zilei"+i+"' onclick='xiaoleclick("+ziarray[i].typeSmallId+","+i+")' style='float:left;width:2.94rem;height:0.8rem;text-align: center;line-height: 0.8rem;border:0.5px solid #c7c7c7;background:#fff;overflow:hidden;font-size:0.36rem'>"+ziarray[i].typeSmallName+"</p>");
		        		 if(ziarray[i].typeSmallId == shoparray[0].typeSmallId){
		        			 xiaoleitiao = i;
		        			 $('.zilei'+i).css({
		    	        		 background:'#b2bfa1',
		    		               color:'#fff'
		    	        	})
		        		 }
		        	}
		        	if(smallId == shoparray[0].typeMiddleId){
		        		xiaoleclick(shoparray[0].typeSmallId,0);
		        	}else{
		        		 $('.zilei0').css({
	    	        		 background:'#b2bfa1',
	    		               color:'#fff'
	    	        	})
	    	        	xuansmall = ziarray[0].typeSmallId;
					       xiaoleclick(ziarray[0].typeSmallId,0);
		        	}
		        	
		        	
		       }
		       
		    });
	  }
	  
	  function xiaoleclick(ji,ff){
		  xuansmall = ji;
		  console.log('子类')
		console.log(ji);
		  console.log(ff);
		if(ji == shoparray[0].typeSmallId){
			 $('.zilei'+xiaoleitiao).css({
				 background:'#b2bfa1',
	               color:'#fff'
	     	}) 
	     	
		}else{
			 $('.zilei'+xiaoleitiao).css({
	     		 background:'#fff',
		               color:'#000'
	     	}) 
	     	xiaoleitiao = ff;
			 $('.zilei0').css({
        		 background:'#b2bfa1',
	               color:'#fff'
        	})
		}
			   
		  var dom;
			var vs = $('.xiugaidisan p');
			var num = vs.length;
		
			for (var i = 0; i < num; i++) {
			  !function(i){
			     
			        $('.zilei'+i).click(function(){
			        	//console.log(i);
			        	if (i == 0) {
					            $('.zilei0').css({
					               background:'#b2bfa1',
					               color:'#fff'
					               })
					    
					      }else{
					            $('.zilei0').css({
					           background:'#fff',
					           color:'#000'
					            })  
					      }
			        	 
			        	
			        	
			       !!dom ? dom.style.color = "":0;
			             !!dom ? dom.style.background = "":0;
			             this.style.color = "#fff";
			             this.style.background = "#b2bfa1";
			             dom = this;
			      });
			      
			  }(i);
			  
			}
	  }
	  //填写资料
	  var shopname = shoparray[0].name;
	  var number = shoparray[0].amount;
	  var unit = shoparray[0].unit;
	  var sendprice = shoparray[0].sendPrice;
	  var anzhuanprice = shoparray[0].installPrice;
	  var pinsendprice = shoparray[0].pinSendPrice;
	  var pinanzhuangprice = shoparray[0].pinInstallPrice;
	  var descript = shoparray[0].remark;
	  
	  $('#spmingzi').val(shopname);
	  $('#spkucunl').val(number);
	  $('#spdanweil').val(unit);
	  $('#spdnajial').val(sendprice);
	  $('#anzhuangid').val(anzhuanprice);
	  $('#miaosu').val(descript);
	  $('.shufuekfk').val(pinsendprice);
	  $('.pinanzhuanf').val(pinanzhuangprice);
	  //商品规格
	  var zhanshigu;
	  var chuangudid;
	  var modelid;
	  var pricarr = shoparray[0].goodsModel;
	  var str = JSON.stringify(pricarr);
	  var xiugaiarray = new Array();
	  xiugaiarray = pricarr;
	  console.log('续费');
	  console.log(xiugaiarray);
	  var picone;
	  //选择商品
	  var pinarray = new Array();
	  var pinxing;
	  var pincarr = shoparray[0].goodsModelPin;
	  pinarray = pincarr;
	  //图片数组
	  var photostate;
	  var photoArray = new Array();
	  //修改图片数组
	  
	  //图片上传
		//添加商品1 
		  if(document.getElementById('shctp1')){
			  initwebuploader();
			  function initwebuploader(){
				  var uploader = WebUploader.create({

					    // 选完文件后，是否自动上传。
					    auto: true,

					    // swf文件路径
					   // swf:'../js/Uploader.swf',

					    // 文件接收服务端。
					    server: basepath+'/upload/upImg.do',

					    // 选择文件的按钮。可选。
					    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
					    pick: {
					    	id:'#filePickerd',
					    	multiple:false,//当个文件 
					    },
					    fileNumLimit: 1,//限制单张
					   // resize : true,//压缩
					    duplicate :true,
					    // 只允许选择图片文件。
					    accept: {
					        title: 'Images',
					        extensions: 'gif,jpg,jpeg,bmp,png',
					        mimeTypes: 'image/*'
					    }
					});
				  
				  uploader.on( 'fileQueued', function( file ) { 
					  $("#fileList").empty();
					  var $list = $("#fileList"), 
					  $li = $( 
					  '<div id="' + file.id + '" class="file-item thumbnail">' + 
					  '<img class="shangchuantu" style="width:8rem">' + '</div>'
					  ), 
					
					  $img = $li.find('img'); 
					   
					   
					  // $list为容器jQuery实例 
					  $list.append( $li ); 
					   
					  // 创建缩略图 
					  uploader.makeThumb( file, function( error, src ) { 
					  if ( error ) { 
					  $img.replaceWith('<span>不能预览</span>'); 
					  return; 
					  } 
					 
					  $img.attr( 'src', src ); 
					  }, 100, 100 ); //100x100为缩略图尺寸 
					 });
				  uploader.on("uploadSuccess", function (file,response) {
					  console.log(response.data.id);
					 
					  picone = response.data.id;
                     if(photostate == 0){
						  photoArray.push(picone);
					  }
				  })
				  uploader.on("uploadFinished", function (file,src) {
					 
				        uploader.destroy();//重复上传,县销毁,在重新启动
				        
				        initwebuploader();
				    });
				  
				  
			  }
			  
			 }
		  
	 // var str =  localStorage.setItem("adfet",str);
	  for(var i = 0;i < pricarr.length;i++){
   		 var div = $('<div id="dd'+pricarr[i].id+'"  class="baoxinghao" onclick="changeguige('+i+','+pricarr[i].id+')"></div>')
   		 div.append('<span id="xinghaozhans chiled1'+pricarr[i].id+'" class="xqxinghaox">'+pricarr[i].model+'</span>'+'<span id="cicunzhans chiled2'+pricarr[i].id+'" class="xqxinghaox">'+pricarr[i].size+'</span>'+'<span id="yansezhans chiled3'+pricarr[i].id+'" class="xqxinghaox">'+pricarr[i].color+'</span>'+'<span id="jiagezhans chiled4'+pricarr[i].id+'" class="xqxinghaox">'+pricarr[i].price+'元</span>')
  
   		var p = $("<p id='dexh"+pricarr[i].id+"' class='addtu7' onclick='delete_system7("+i+","+pricarr[i].id+")'></p>")
   		 var img = $('<img id="photos'+pricarr[i].id+'" class="xingtu" src="'+basepath+'/attachment/'+pricarr[i].imgUrl+'.do" />');
   		  $('.donttianjia').append(div);
   		$('.donttianjia').append(p);
   		$('.donttianjia').append(img);
   	  }
	  function delete_system7(pi,flag){
		  console.log(xiugaiarray);
		  console.log(flag);
			//根元素不删除
		  for(var i = 0;i < xiugaiarray.length;i++){
			  if(xiugaiarray[i].id == flag){
				  xiugaiarray.splice(i,1);
				  console.log(xiugaiarray);
				   document.getElementById("dd" + flag + "").remove();
				   document.getElementById("dexh" + flag + "").remove();
				   document.getElementById("photos" + flag + "").remove();
				   delete_system9(pi,flag);
			  }
		  }
		 
	    
			}
	  $('.xqxinghao').click(function(){
		  photostate = 0;
		  var count = xiugaiarray.length + zongguiarr.length;
		  console.log('数量多少');
		  console.log(count);
		  console.log(xiugaiarray);
		  console.log(zongguiarr.length);
		  if(3 - count > 0){
			  $('.tishi').css({
				  display:'block'
			  })
			  zhanshigu = 0;
			  picone = 0;
		  }else{
			  alert('最多只能添加三个规格');
		  }
		  
	  })
	  //编辑商品规格
	 
	  function changeguige(modeldarr,guid){
		  zhanshigu = 1;
		  chuangudid = guid;
		  modelid = modeldarr;
		  picone = 0;
		  console.log(modeldarr);
		  $('.tishi').css({
			  display:'block'
		  })
		  var yiguiarr = shoparray[0].goodsModel;
		 
		  $('.guiged').val(yiguiarr[modeldarr].model);
		  $('.chicun').val(yiguiarr[modeldarr].size);
		  $('.yanse').val(yiguiarr[modeldarr].color);
		  $('.jiage').val(yiguiarr[modeldarr].price);
		   var pic3 = yiguiarr[modeldarr].imgUrl;
           var path = basepath+'/attachment/'+pic3+'.do';
           console.log(path);
          
  	      $('#fileList').css({
  		    background:"url("+path+")  no-repeat center",
  	        backgroundSize: 'cover'
  	      })
	  }
	  
	  
	  function delete_system6(pi,flag){
			//根元素不删除
		  for(var i = 0; i < xiugaiarray.length; i ++){
			  if(xiugaiarray[i].id == flag){
				  xiugaiarray.splice(pi,1);
				     console.log(xiugaiarray);
				     document.getElementById("dd" + flag + "").remove();
					   document.getElementById("dexh" + flag + "").remove();
					   document.getElementById("photos" + flag + "").remove();
			  }
		  }
		 
			
			   
			}
	  //添加商品规格
	  var addguigarr = new Array();
	  var zongguiarr = new Array();
	 var appdd = 0;
	  $('.quedind').click(function(){
		  
		  $('.tishi').css({
			  display:'none'
		  })
		  if(zhanshigu == 1){
			  delete_system6(modelid,chuangudid);
			  var changguig = $('.guiged').val();
			  var changcicun = $('.chicun').val();
			  var changecolor =  $('.yanse').val();
			  var changprice = $('.jiage').val();
			  var goodsid = chuangudid;
			  var pinprice;
			
			  console.log('修改');
			  console.log(xiugaiarray);
			  var oop= [];
			  oop['model'] = changguig;
			  oop['size'] = changcicun;
			  oop['color'] = changecolor;
			  oop['price'] = changprice;
			  oop['pic'] = picone;
			  oop['id'] = goodsid;
			  xiugaiarray.push(oop);
			  console.log(xiugaiarray);
			var div= $('<div id="dd'+chuangudid+'"  class="baoxinghao" onclick="changeguige('+modelid+','+chuangudid+')"></div>');
			 div.append('<span id="xinghaozhans " class="xqxinghaox">'+changguig+'</span>'+'<span id="cicunzhans" class="xqxinghaox">'+changcicun+'</span>'+'<span id="yansezhans" class="xqxinghaox">'+changecolor+'</span>'+'<span id="jiagezhans" class="xqxinghaox">'+changprice+'元</span>')
			 var p = $("<p id='dexh"+chuangudid+"' class='addtu7' onclick='delete_system7("+modelid+","+chuangudid+")'></p>");
			 var img = $('<img id="photos'+chuangudid+'" class="xingtu" src="'+basepath+'/attachment/'+picone+'.do"  />');
			 $('.donttianjia').prepend(img);
			 $('.donttianjia').prepend(p);
			 $('.donttianjia').prepend(div);
			
			 if(pincarr[modelid].goodsModelId == chuangudid){
				 pinprice = pincarr[modelid].pinPrice;
				 delete_system9(modelid,chuangudid);
				 var div1= $('<div id="pinx'+chuangudid+'"  class="baoxinghao" ></div>');
				 div1.append('<span id="xinghaozhans " class="xqxinghaox pinxiaodd">'+changguig+'</span>'+'<span id="cicunzhans" class="xqxinghaox pinxiaodd">'+changcicun+'</span>'+'<span id="yansezhans" class="xqxinghaox pinxiaodd">'+changecolor+'</span>'+'<span id="jiagezhans" class="xqxinghaox pinxiaodd">'+pinprice+'元</span>')
				 var p1 = $("<p id='pinxh"+chuangudid+"' class='addtu7' onclick='delete_system9("+modelid+","+chuangudid+")'></p>");
				 $('.pinxuanzdongtaijia').append(div1);  
				 $('.pinxuanzdongtaijia').append(p1);
				 var pinoop = [];
				 pinoop['model'] = changguig;
				 pinoop['size'] = changcicun;
				 pinoop['color'] = changecolor;
				 pinoop['pinPrice'] = pinprice;
				 pinoop['goodsModelId'] = chuangudid;
				 pinoop['id'] = pincarr[modelid].id;
				 pinarray.push(pinoop);
				 console.log('拼单啦');
				 console.log(pinarray);
			 }
			 
		  }else if(zhanshigu == 0){
			  var guige = $('.guiged').val();
			  var cicun = $('.chicun').val();
			  var collor = $('.yanse').val();
			  var pprice = $('.jiage').val();
			  addguigarr.splice(0,addguigarr.length);
			  addguigarr["model"] = guige;
			  addguigarr["size"] = cicun;
			  addguigarr["color"] = collor;
			  addguigarr["price"] = pprice;
			 
			  var k = [];
			  k["model"] = addguigarr.model;
			  k["size"] = addguigarr.size;
			  k["color"] = addguigarr.color;
			  k["price"] = addguigarr.price;
			  k['pic'] = picone;
			  zongguiarr.push(k);
			  console.log(zongguiarr);
			  $('.donttianjiadf').empty();
			  if(picone == 0){
				  alert('请添加图片');
		   			//photoArray.push('79849052-91e1-458a-a705-4c44f3535400');
		   		}else{
		   		  for(var i = 0;i < zongguiarr.length;i++){
					  var div = $('<div id="ddbvbf'+i+'" class="baoxinghao"></div>')
				   		 div.append('<span id="xinghaozhans" class="xqxinghaox">'+zongguiarr[i].model+'</span>'+'<span id="cicunzhans" class="xqxinghaox">'+zongguiarr[i].size+'</span>'+'<span id="yansezhans" class="xqxinghaox">'+zongguiarr[i].color+'</span>'+'<span id="jiagezhans" class="xqxinghaox">'+zongguiarr[i].price+'元</span>')
				  
				   		var p = $("<p id='dexhbfbf"+i+"' class='addtu7' onclick='delete_system8("+i+")'></p>");
					  var img = $('<img id="photoees'+i+'" class="xingtu" src="'+basepath+'/attachment/'+photoArray[i]+'.do"  />');
				   		  $('.donttianjiadf').append(div);
				   		$('.donttianjiadf').append(p);
				   		$('.donttianjiadf').append(img);
				   		console.log('图片展示');
				   		
				   		console.log(photoArray);
				   		
				  }
		   		}
			
			  appdd++;
		  }
		
	  })
	  function delete_system8(flag){
			//根元素不删除
		  console.log(flag);
		  zongguiarr.splice(flag,1);
		  photoArray.splice(flag,1);
	     console.log(zongguiarr);
			   document.getElementById("ddbvbf" + flag + "").remove();
			   document.getElementById("photoees" + flag + "").remove();
			   document.getElementById("dexhbfbf" + flag + "").remove();
			   delete_system10(flag)
			}
	  
	  
	  //选择商品规格
	
	  var xianzpinde = new Array();
	  var zongxianpinda = new Array();
	  $('.xuanzcdhai').click(function(){
		    $('.xuanzvhai').css({
		      display:'block'
		    })  
		    
		    var p = [];
		    $('.xinghaohuizong').empty();
		    for (var i = 0; i < zongguiarr.length; i++) {
		    
		    p = zongguiarr[i];
		    var div = $('<div id="bc'+i+'" class="baoyiceng2" onclick="tanchuyinclick('+i+')"></div>');
		     var span = "<p id='xh"+p.model+"' class='xqxinghaox'>"+p.model+"</p>"+"<p id='xh"+p.model+"'  class='xqxinghaox'>"+p.size+"</p>"+"<p id='xh"+p.model+"'  class='xqxinghaox'>"+p.color+"</p>"+"<p id='xh"+p.model+"'  class='xqxinghaox'>"+p.price+"</p>";
		    div.append(span);
		    $('.xinghaohuizong').append(div);
		  }
		})
		function tanchuyinclick(h){
		   $('.xuanzvhai').css({
		      display:'none'
		    })
		   $('.pindandanjia').css({
		      display:'block'
		    })
		   pinxing = h;
		   console.log(h);
		   $('.pindanxinhao').empty();
		   var d = zongguiarr[h];
		   var div = $('<div id="zs'+d.id+'" class="baoxinghao"></div>');
		   var span = "<p id='xh"+d.model+"' class='xqxinghaox'>"+d.model+"</p>"+"<p id='xh"+d.model+"'  class='xqxinghaox'>"+d.size+"</p>"+"<p id='xh"+d.model+"'  class='xqxinghaox'>"+d.color+"</p>"+"<p id='xh"+d.model+"'  class='xqxinghaox'>"+d.price+"</p>";   
		   div.append(span);
		
		    $('.pindanxinhao').append(div);
		
		}
		$('.pindanjiat').click(function(){
			 $('.pindandanjia').css({
			      display:'none'
			    })
			    var pinprice = $('.pindanjiage').val();
			    var w = zongguiarr[pinxing];
			    console.log(w);
			    xianzpinde.splice(0,xianzpinde.length);
			    xianzpinde["goodsModelId"] = w.model;
			    xianzpinde["size"] = w.size;
			    xianzpinde["color"] = w.color;
			    xianzpinde["pinPrice"] = pinprice;
			    var dp = new Array();
			    dp["goodsModelId"] = xianzpinde.goodsModelId;
			    dp["size"] = xianzpinde.size;
			    dp["color"] = xianzpinde.color;
			    dp["pinPrice"] = xianzpinde.pinPrice;
			    zongxianpinda.push(dp);
			   console.log(zongxianpinda);
			    
				 var divv = $('<div id="pxdfj'+pinxing+'" class="baoxinghao"></div>');
				 var span = "<p id='xh"+w.model+"' class='xqxinghaox pinxiaodd'>"+w.model+"</p>"+"<p id='xh"+w.model+"'  class='xqxinghaox pinxiaodd'>"+w.size+"</p>"+"<p id='xh"+w.model+"'  class='xqxinghaox pinxiaodd'>"+w.color+"</p>"+"<p id='xh"+w.model+"'  class='xqxinghaox pinxiaodd'>"+pinprice+"元</p>";
				var p = "<p id='dfdfe"+pinxing+"' class='addtu7' onclick='delete_system10("+pinxing+")'></p>";
				$('.pinxuanzdongtaijia').append(divv);  
				$('.pinxuanzdongtaijia').append(p);  
				divv.append(span);
		})
		function delete_system10(flag){
			zongxianpinda.splice(flag,1);
			console.log(zongxianpinda);
			 document.getElementById("pxdfj" + flag + "").remove();
			   document.getElementById("dfdfe" + flag + "").remove();
		}
		
		$('.pindanqu').click(function(){
			 $('.pindandanjia').css({
			      display:'none'
			    })	    
		})
		$('.xuanzvhai').click(function(){
		    $('.xuanzvhai').css({
		      display:'none'
		    })  
		    
		})
		console.log('wwww');
		console.log(pricarr);
		
		for(var i = 0;i < pincarr.length;i++){
	      	
     		 var div = $('<div id="pinx'+pricarr[i].id+'" class="baoxinghao baonao"></div>');
     		  div.append('<span id="xinghaozhans" class="xqxinghaox pinxiaodd">'+pricarr[i].model+'</span>'+'<span id="cicunzhans" class="xqxinghaox pinxiaodd">'+pricarr[i].size+'</span>'+'<span id="yansezhans" class="xqxinghaox pinxiaodd">'+pricarr[i].color+'</span>'+'<span id="jiagezhans" class="xqxinghaox pinxiaodd">'+pincarr[i].pinPrice+'元</span>')
     		var p = $("<p id='pinxh"+pricarr[i].id+"' class='addtu7' onclick='delete_system9("+i+","+pricarr[i].id+")'></p>")
     		  $('.pinxuanzdongtaijia').append(div);
     		  $('.pinxuanzdongtaijia').append(p);
     	  }
		console.log(pinarray);
	  function delete_system9(pis,flag){
		  for(var i = 0;i < pinarray.length;i++){
			  if(pinarray[i].goodsModelId == flag){
				  pinarray.splice(i,1);
				  
				  console.log(pinarray);
				  document.getElementById("pinx" + flag + "").remove();
				   document.getElementById("pinxh" + flag + "").remove();
			  }
		  }
			  
			  
		 
		 
	  }
	 

  	  var peisYorN ;
  	  var anzhuangYorN;
  	  var swithch;
  	  var pinPeople;
  	  var pinTimee;
  	  var pinpeisYorN;
  	  var pinanzhuangYorN;
  	  
	//否免费配送
  	peisYorN = 1;
		function peisongclick(){
		  var peisongf = document.getElementById('peisonggaoqi').peisong;
		   for (var i = 0; i < peisongf.length; i++) {
		    if (peisongf[i].checked) {
		      var pesf = peisongf[i].value;
		    console.log(pesf);
		    peisYorN  = pesf;
		  }
		    
		}
		}
		//是否免费安装
		anzhuangYorN = 1;
		function anzhuangclick(){
		  var pinaz = document.getElementById('anzhuagngaoqi').anzhuang;
		   for (var i = 0; i < pinaz.length; i++) {
		    if (pinaz[i].checked) {
		      var pesf = pinaz[i].value;
		    console.log(pesf);
		    anzhuangYorN  = pesf;
		  }
		    
		}
		}
		
		
		//开关
		 var chk = document.getElementById('ios-checkbox');
		  console.log(chk.checked);
		  swithch = 1;
		function kaiguan(){
		 
		if (chk.checked == false) {
			swithch  = 0;
		  console.log(chk.checked);
		}else{
			swithch  = 1;
		  console.log(chk.checked);
		}
		/*if(pinYN == 0){
			$('.shifouzhankai').css({
				display:'block'
			})
		}else{
			$('.shifouzhankai').css({
				display:'none'
			})
		}
		*/
	}
		
		//拼单人数
		//pinrenNumber = 2;
		function seldctpinren(){
			var sel = document.getElementById('pinren');
			var selected_val = sel.options[sel.selectedIndex].value;
			var select_text = $('#pinren option:selected').text();
			pinPeople = selected_val;
			console.log(selected_val);
			
			}
		//p拼单周期
		pinTimee = 3;
		function seldcttime(){
			var pintime = document.getElementById('pintime');
			var pintime_val = pintime.options[pintime.selectedIndex].value;
			var pintime_text = $('#pintime option:selected').text();
			pinTimee = pintime_val;
			console.log(pintime_val);	
			}
		//拼团是否免费配送
		pinpeisYorN = 1;
		function pinpeisongclick(){
		  var peisongf = document.getElementById('pinpeisongfei').pinpeisong;
		   for (var i = 0; i < peisongf.length; i++) {
		    if (peisongf[i].checked) {
		      var pesf = peisongf[i].value;
		    console.log(pesf);
		    pinpeisYorN  = pesf;
		  }
		    
		}
		}
		//拼团是否免费安装
		pinanzhuangYorN = 1;
		function pinanzhuangclick(){
		  var pinaz = document.getElementById('pinanzhuangfei').pinanzhuang;
		   for (var i = 0; i < pinaz.length; i++) {
		    if (pinaz[i].checked) {
		      var pesf = pinaz[i].value;
		    console.log(pesf);
		   pinanzhuangYorN  = pesf;
		  }
		    
		}
		}
		var goodsName;
		var goodsNum;
		var sendprice;
		var anzhuangprice;
		var unite;
		var remark;
  	    var zuizongarray = new Array();
  	    var pinzuizongarray = new Array();
  	 // xiugaiarray  zongguiarr  pinarray zongxianpinda
  	
  	console.log(zongguiarr);
  	var jp = [];
    var kp = [];
    var pj = [];
    var pk = [];
  	  $('.bcuocunxiugai').click(function(){
  		zuizongarray.splice(0,zuizongarray.length);
  		pinzuizongarray.splice(0,pinzuizongarray.length);
  		  if(xiugaiarray.length != 0){
  			  
  			  for(var i = 0;i < xiugaiarray.length; i++){
  				  jp = xiugaiarray[i];
  				zuizongarray.push(jp);
  			  }
  		  }
  		  if(zongguiarr.length != 0){
  			
  			 for(var i = 0;i < zongguiarr.length; i++){
  				 kp = zongguiarr[i];
				zuizongarray.push(kp);
  			 }
  		  }
  		
  		 if(pinarray.length != 0){
   			
  			 for(var i = 0;i < pinarray.length; i++){
  				pj = pinarray[i];
  				pinzuizongarray.push(pj);
  			 }
  		  }
  		 if(zongxianpinda.length != 0){
    			
  			 for(var i = 0;i < zongxianpinda.length; i++){
  				pk = zongxianpinda[i];
  				pinzuizongarray.push(pk);
  			 }
  		  }
  	  /*	pinzuizongarray.push(pinarray);
  	  pinzuizongarray.push(zongxianpinda);*/
  		 console.log('提交');
  	  	 console.log(zuizongarray);
  	  	console.log(pinzuizongarray);
  	  
  		goodsName = $('#spmingzi').val();
  		goodsNum = $('#spkucunl').val();
  		unite = $('#spdanweil').val();
		 sendprice  = $('#spdnajial').val();
		 anzhuangprice  = $('#anzhuangid').val();
		 remark  = $('#miaosu').val();
		 pinsendPrice  = $('.shufuekfk').val();
		 pinanzhuangPrice  = $('.pinanzhuanf').val();
		 
		 
		 var customerArray = new Array();
		 var pincustomerArray = new Array();
		 var picarray = new Array();
		 for(var i = 0;i<zuizongarray.length;i++){
			 customerArray.push({id:zuizongarray[i].id, model:zuizongarray[i].model,size:zuizongarray[i].size,color:zuizongarray[i].color,price:zuizongarray[i].price});
		 }
		 for(var i = 0;i<pinzuizongarray.length;i++){
			 pincustomerArray.push({goodsModelId:pinzuizongarray[i].goodsModelId,pinPrice:pinzuizongarray[i].pinPrice});
		 }
		/* picarray.push({goodsId:'',resourseId:pic3});
		 picarray.push({goodsId:'',resourseId:pic4});*/
		 pincustomerArray.push({goodsModelId:'',pinPrice:'12',});
		 pincustomerArray.push({goodsModelId:'',pinPrice:'14',});
		 console.log(customerArray);
		 console.log(pincustomerArray);
		 var urltianjia = basepath+'/goods/save2.do';
		  var data = {
				  id:"55",
				  name:goodsName,
				  amount:goodsNum,
				  unit:unite,
				  freeSend:peisYorN,
				  sendPrice:sendprice,
				  hasInstall:anzhuangYorN,
				  installPrice:anzhuangprice,
				  description:remark,
				  typeBigId:xuanbig,
				  typeMiddleId:xuanmiddle,
				  typeSmallId:xuansmall,
				  useId:"",
				  remark:"",
				  isOpenpin:swithch,
				  pinNums:pinPeople,
				  pinTime:pinTimee,
				  pinFreeSend:pinpeisYorN,
				  pinSendPrice:pinsendPrice,
				  pinHasInstall:pinanzhuangYorN,
				  pinInstallPrice:pinanzhuangPrice,
				  goodsPic:picarray,
				  goodsModel:customerArray,
				  goodsModelPin:pincustomerArray,
				  };
		 
		  console.log(data);
		  $.ajax({
			  	contentType : "application/json ; charset=utf-8",
			  	url:urltianjia,
		        async:false,
		        type:"post",
		        dataType: "json", 
		        data:JSON.stringify(data),
		        success:function(result){
		        	console.log(result);
		        	//sessionStorage.removeItem(xing);
		        	
		       }
		 
		    });
	 
  	  });
  	  
  	 
  	  
}


//网络请求之我的订单
if (document.getElementById('clswodedidan')) {
  var ticketList = new Array(
  {
    "bianhao":"2007030190901",
    "time":"2017-1-2 12:00:00",
    "zhonglei":"3",
    "shuliang":"13",
    "zongjine":"100.00",
    "weifa":"0",
    "pindan":"0"
   },
   {
    "bianhao":"2007030190901",
    "time":"2017-1-2 12:00:00",
    "zhonglei":"3",
    "shuliang":"13",
    "zongjine":"200.00",
    "weifa":"1",
    "pindan":"0"
   },
   {
    "bianhao":"2007030190901",
    "time":"2017-1-2 12:00:00",
    "zhonglei":"3",
    "shuliang":"13",
    "zongjine":"200.00",
    "weifa":"1",
    "pindan":"1"
   }
   );
 localStorage.setItem("dic", ticketList[0]);
 for (var i = 0; i < ticketList.length; i++) {
      var divv = $('<div class="ticketxiang" onclick="dingdanxiangqing('+i+')"></div>');
      var ull = $('<ul></ul>');
      var lii = $('<li class="tickdd"></li>');
      var lii2= $('<li class="tickdd"></li>');
      var lii3= $('<li class="tickdd"></li>');
      var lii4= $('<li class="tickdd"></li>');
      lii.append('<p class="tickfiest"><b>订单编号：</b><span class="bianhaoxiangqing">'+ticketList[i].bianhao+'</span></p> '+'<p class="ticksubfiset">'+ticketList[i].time+'</p>');
      lii2.append('<p class="tickfiest"><b>购买种类：</b><span class="bianhaoxiangqing">'+ticketList[i].zhonglei+'</span></p> ');
      lii3.append('<p class="tickfiest dfsd"><b>购买数量：</b><span class="bianhaoxiangqing">'+ticketList[i].shuliang+'</span></p> '+'<p class="tickright"></p>');
      
      if (ticketList[i].weifa == "1" && ticketList[i].pindan == "0") {
       lii4.append('<p class="tickfiest zongjied"><b>总支付金额：</b><span class="ticketmoney">¥'+ticketList[i].zongjine+'</span></p> '+'<p class="pindan" style="background:#fff"></p>'+'<p class="tickthirst yifahuo">已发货</p>');
      }else if(ticketList[i].weifa == "1" && ticketList[i].pindan == "1"){
        lii4.append('<p class="tickfiest zongjied"><b>总支付金额：</b><span class="ticketmoney">¥'+ticketList[i].zongjine+'</span></p> '+'<p class="pindan">拼</p>'+'<p class="tickthirst yifahuo">已发货</p>');
      }
      else if (ticketList[i].weifa == "0" && ticketList[i].pindan == "0"){
        lii4.append('<p class="tickfiest zongjied"><b>总支付金额：</b><span class="ticketmoney">¥'+ticketList[i].zongjine+'</span></p> '+'<p class="pindan" style="background:#fff"></p>'+'<p class="tickthirst">未发货</p>');
      }else{
        lii4.append('<p class="tickfiest zongjied"><b>总支付金额：</b><span class="ticketmoney">¥'+ticketList[i].zongjine+'</span></p> '+'<p class="pindan"></p>'+'<p class="tickthirst">未发货</p>');
      }
      ull.append(lii);
      ull.append(lii2);
      ull.append(lii3);
      ull.append(lii4);
      divv.append(ull);
     $('.ticketxiangyifu').append(divv);
 }
   var pindnt;
   function dingdanxiangqing(i){
    if (ticketList[i].pindan == "0") {
       pindnt = 0;
       localStorage.setItem("pindnt", "0");
    }else if (ticketList[i].pindan == "1") {
       pindnt = 1;
       localStorage.setItem("pindnt", "1");
    }
   
    window.location.href = "CLS_DD_DingDXQ.html";
}
}
 
 //订单详情
 if (document.getElementById('clsdingdanxiangqingye')){
  var dic = localStorage.getItem("dic");
console.log(dic.pindan);

var pindanxis = localStorage.getItem("pindnt"); 
if (pindanxis == 0) {
  $('.yhzong').css({
    display:'block'
  })
   $('.pindanxiangqing').css({
    display:'none'
  })
 }else if (pindanxis == 1) {
  $('.yhzong').css({
    display:'none'
  })
   $('.pindanxiangqing').css({
    display:'block'
  })
 }
 }
 //商品管理
 if (document.getElementById('liullist')){
	 var url = basepath+'/market/findShop.do';
		
	var data = {userId:'4'};
	 $.ajax({
	        url:url,
	        type:"post",
	        data:data,
	        success:function(result){
	        	console.log(result);
	        	var myDian = result.data;
	        	var typename = myDian.marketTypeName;
	        	var markName = myDian.marketName;
	        	var areaName = myDian.marketAreaName;
	        	var shopAdress = myDian.adress;
	        	var shopName = myDian.shopName;
	        	$('#sclexing').html(typename);
	        	$('#scmingzi').html(markName);
	        	$('#sccquwei').html(areaName);
	        	$('#scxiangaderss').html(shopAdress);
	        	$('#scjiamingzi').html(shopName);
	  
	        		  
	       }
	    });
  /*var myDian = new Array(
 "本地材料市场","黄台建材市场","1区地板类","1区502-1","双喜熟料版","http://fuzhoutest.scity.cn/image/get/system/default/01eeac42fbfcb1699b848e787e8af955.jpg");
 var lilist = $('.dingdansubf');
  for (var i = 0; i < lilist.length; i++) {
    lilist[i].innerHTML = myDian[i];
  }
  var imgurl = myDian[5];
   $('#shopjiatoujcsj').attr("src",myDian[5]);*/
 }
 
 